//
//  FirstViewController.m
//  ImitateJDjrApp
//
//  Created by srj on 2018/6/6.
//  Copyright © 2018年 168licai. All rights reserved.
//

#import "FirstViewController.h"
#import "AppDelegate.h"
#import "RootViewController.h"

@interface FirstViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>
@property (strong, nonatomic) UILabel *titleLbl;
@property (strong, nonatomic) UIView *headerView;

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.titleLbl];
    [self.titleLbl setFrame:CGRectMake(0,kUISCREEN_HEIGHT/2, kUISCREEN_WIDTH, 20)];
    self.titleLbl.text = @"第1页";
    [self.view addSubview:self.tableView];
    
    
    self.tableView.tableHeaderView = self.headerView;
    
//    [self.tableView setContentInset:UIEdgeInsetsMake(CGFloat top, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 48;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor yellowColor];
    return view;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = @"1234234";
    return cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    NSLog(@"%f",offsetY);
    [((RootViewController *)self.parentViewController).topScrollView setFrame:CGRectMake(kTOPSCROLLVIEWSPACE, -offsetY, kTOPSCROLLVIEWWIDTH, 200)];
    UITableView *sTableView = ((RootViewController *)self.parentViewController).secondVC.tableView;
    [sTableView setContentOffset:CGPointMake(0, offsetY)];
    ((RootViewController *)self.parentViewController).secondVC.tableView = sTableView;
}

- (UITableView *)tableView
{
    if (!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kUISCREEN_WIDTH, kUISCREEN_HEIGHT-kTopHeight-kBottomHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (UIView *)headerView
{
    if (!_headerView){
        _headerView = [[UIView alloc] init];
        _headerView.frame = CGRectMake(0, 0, kUISCREEN_WIDTH, 300);
        _headerView.backgroundColor = [UIColor redColor];
    }
    return _headerView;
}
- (UILabel *)titleLbl
{
    if (!_titleLbl){
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = [UIFont systemFontOfSize:16];
        _titleLbl.textColor = [UIColor blueColor];
    }
    return _titleLbl;
}
@end
